'''
Created on Jun 7, 2010

@author: Behrooz Nobakht
'''
from django import forms
from django.forms.util import flatatt
from django.utils.safestring import mark_safe

class AdvertizerSelectWidgetWrapper(forms.Select):
    
    return_url = '/'
    
    def __init__(self, attrs=None, choices=(), return_url='/'):
        super(AdvertizerSelectWidgetWrapper, self).__init__(attrs, choices)
        self.return_url = return_url
        
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = ''
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<select%s>' % flatatt(final_attrs)]
        options = self.render_options(choices, [value])
        if options:
            output.append(options)
        output.append(u'</select>')
        output.append(u'<a href="/ads/advertizer/register/?return=%s">+</a>' % self.return_url)
        return mark_safe(u'\n'.join(output))

        
    
